package com.lft.freshordering.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lft.freshordering.entity.Goods;
import com.lft.freshordering.entity.Stypes;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tyhxzy
 * @since 2024-12-02
 */
//我的代码

public interface StypesMapper extends BaseMapper<Stypes> {
//查询所有商品类型
    @Select("SELECT * \n" +
            "FROM stypes")
    List<Stypes> selectAll();

//查询分类商品
    @Select("SELECT * \n" +
            "FROM goods,stypes\n" +
            "WHERE stypes.id=goods.category_id and stypes.id=#{id}")
    List<Goods> selectByType(Integer id);

    //查询商品详情
    @Select("SELECT * \n" +
            "FROM goods,goods_unit\n" +
            "WHERE goods.goods_unit=goods_unit.unit_id AND goods_name=#{name}")
    Goods selectByName(String name);

    //查询所有商品
    @Select("SELECT * \n" +
            "FROM goods")
    List<Goods> selectAllGoods();

    //搜索框查询
    @Select("SELECT *\n" +
            "FROM goods\n" +
            "WHERE goods_name LIKE CONCAT('%', #{goodsName}, '%');")
    List<Goods> sou(String goodsName);







    @Select("SELECT * FROM stypes ORDER BY num;")
    List<Stypes> selectStypes();





    @Delete("delete from stypes where id=#{id}")
    int deletestypes(Integer id);

    @Select("select * from stypes")
    List<Stypes> selectStypess();

    //查询所有商品
    @Select("select * from goods where is_deleted=0 and category_id=#{id} order by goods_id desc")
    List<Goods> selectGoodsByCategoryId(Integer id);

    @Select("select id from stypes where num=#{num}")
    Integer selectss(Integer num);



    @Update("update stypes set num=#{num2},tname=#{tname} where id=#{id}")
    int updatestypes(Integer id,  Integer num2,  String tname);

    @Update("update stypes set num=#{num} where id=#{id2}")
    int updatestypes2(Integer id2, Integer num);

    // 查询num最大值
    @Select("SELECT MAX(num) FROM stypes")
    Integer selectMaxNum();

    @Insert("insert into stypes(tname,num) values(#{tname},#{num})")
    int inserttname(Stypes stypes);




}
